package com.nami.store.biz.sendboxmsgs.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nami.store.domain.SendboxMsgsDO;
import com.nami.store.mapper.SendboxMsgsMapper;
import com.nami.store.biz.sendboxmsgs.repository.SendboxMsgsRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.utils.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *
 * </p>
 *
 * @author lbc
 * @since 2024-06-15
 */
@Service
@Slf4j
@AllArgsConstructor
public class SendboxMsgsServiceImpl implements SendboxMsgsRepository {

    private final SendboxMsgsMapper baseMapper;

    @Override
    public boolean save(SendboxMsgsDO sendboxMsgs) {
        baseMapper.insert(sendboxMsgs);
        return Boolean.TRUE;
    }

    @Override
    public boolean delByTime(String appKey, Date time) {
        if (StringUtils.isBlank(appKey) || time == null) {
            return Boolean.FALSE;
        }
        Integer result = baseMapper.delete(new LambdaQueryWrapper<SendboxMsgsDO>()
            .eq(SendboxMsgsDO::getAppKey, appKey)
            .le(SendboxMsgsDO::getSendTime, time)
        );
        log.info("[sendboxmsgs] 删除成功，appKey={}. size={}", appKey, result);
        return Boolean.TRUE;
    }
}
